<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_cal.tpl'}-->
    <title>添加用户</title>
    <!--{include file='comm/comm_region.tpl'}-->
    <!--{include file="comm/icheck.tpl"}-->
    <!--{include file='comm/comm_editor.tpl'}-->
</head>
<body>
<div style="width:100%">

    <div class="container">
        <div class="comm_crub">
            <span class="now_crub">正在操作：添加用户</span>
        </div>
        <div class="comm_content">
            <form id="edit_form" class="form-horizontal" onsubmit="return false;">
                <div class="commAttr">
                    <div class="form-group">
                        <label for="" class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            <font color="red">注册成功后系统会将用户登录密码发送到用户注册手机上*</font>
                        </div>
                     </div>
                    <div class="form-group">
                        <label for="custID" class="col-sm-2 control-label"><span class="red">*</span> 会员名：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="custID" name="custID" placeholder="请输入会员名【手机号码】">

                            <div style="color:red;" id="custname_error"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="nickName" class="col-sm-2 control-label"> 昵称：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="nickName" name="nickName" placeholder="请输入昵称">
                        </div>
                        <input type="hidden" name="pcustID" id="pcustID" value="0" />
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"> 头像：</label>
                        <div class="col-sm-10">
                            <button type="button" class="btn btn-default" id="update_head_pic">点击上传头像</button>
                            <div id="head_pic_box" style="display: none;margin-top: 5px;"></div>
                            <input type="hidden" name="head_pic" id="head_pic" value="" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="custname" class="col-sm-2 control-label"><span class="red">*</span> 会员姓名：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="custname" name="custname" placeholder="请输入会员姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="phone" class="col-sm-2 control-label"> 固定电话：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="phone" name="phone" placeholder="请输入电话号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mobile" class="col-sm-2 control-label"> 手机号码：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="mobile" name="mobile" placeholder="请输入手机号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="email" class="col-sm-2 control-label"> 邮箱：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w500" id="email" name="email" placeholder="请输入邮箱地址">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label"> 性别：</label>
                        <div class="col-sm-10">
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="sexy-radio-1" name="sexy" value="1">
                                <label for="sexy-radio-1">男</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="sexy-radio-2" name="sexy" value="2">
                                <label for="sexy-radio-2">女</label>
                            </div>
                            <div class="fl">
                                <input type="radio" class="square-radio" id="sexy-radio-0" name="sexy" value="0" checked>
                                <label for="sexy-radio-0">保密</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="birthday" class="col-sm-2 control-label"><span class="red">*</span> 生日：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control input-sm" id="birthday" name="birthday" style="width:100px;" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label"> 会员来源：</label>
                        <div class="col-sm-10">
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-1" name="custSource" value="1">
                                <label for="custSource-radio-1">PC</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-2" name="custSource" value="2">
                                <label for="custSource-radio-2">WAP</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-3" name="custSource" value="3">
                                <label for="custSource-radio-0">APP</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-4" name="custSource" value="4">
                                <label for="custSource-radio-4">微信</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-5" name="custSource" value="5" checked>
                                <label for="custSource-radio-5">客服</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-6" name="custSource" value="6">
                                <label for="custSource-radio-6">第三方</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custSource-radio-7" name="custSource" value="7">
                                <label for="custSource-radio-7">线下</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label"> 用户类型：</label>
                        <div class="col-sm-10">
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custType-radio-1" name="custType" value="1" checked>
                                <label for="custType-radio-1">普通会员</label>
                            </div>
                            <div class="fl" style="margin-right: 10px;">
                                <input type="radio" class="square-radio" id="custType-radio-2" name="custType" value="2">
                                <label for="custType-radio-2">访客会员</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span class="red">*</span> 省市区：</label>
                        <div class="col-sm-10">
                            <select class="form-control fl" id="provinceid" name="provinceid" style="width: 100px;margin-right: 5px;">
                                <option value="">请选择...</option>
                            </select>
                            <select class="form-control fl" id="cityid" name="cityid" style="width: 100px;margin-right: 5px;">
                                <option value="">请选择...</option>
                            </select>
                            <select class="form-control fl" id="countyid" name="countyid" style="width: 100px;">
                                <option value="">请选择...</option>
                            </select>
                        </div>
                        <input type="hidden" id="provinceName" name="provinceName" value="" />
                        <input type="hidden" id="cityName" name="cityName" value="" />
                        <input type="hidden" id="countyName" name="countyName" value="" />
                    </div>

                    <div class="form-group">
                        <label for="address" class="col-sm-2 control-label"><span class="red">*</span> 详细地址：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w500" id="address" name="address" placeholder="请输入居住地址">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="identityCard" class="col-sm-2 control-label"> 身份证号码：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control w300" id="identityCard" name="identityCard" placeholder="请输入身份证号码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"> 月收入：</label>
                        <div class="col-sm-10">
                            <select class="form-control w150 fl" name="monthlyIncome" id="monthlyIncome" >
                                <option value="0" selected>无收入</option>
                                <option value="1">2000元以下</option>
                                <option value="2">2000-3999元</option>
                                <option value="3">4000-5999元</option>
                                <option value="4">6000-7999元</option>
                                <option value="5">8000元以上</option>
                            </select>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>


    <div class="popup-footer">
        <div class="rectbox tac" style="margin: 20px;">
            <input type="button" class="btn btn-success" onclick="customer.check();" value="保存" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>



</div>

<script type="text/javascript">

    $(window).ready(function() {

        $('.square-radio').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });

    });
	
	$(document).ready(function(){
		$('#custname_error').hide();
		
		$('#custID').blur(function(){
			$.ajax({
                type: "GET",
                url: "/invokingAjax-backend/customer/customer.ajax?operFlg=22&custID="+$(this).val(),
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code != 200) {
                        $('#custname_error').show();
                        $('#custname_error').text(result_obj.message);
                    }else{
                    	$('#custname_error').text('');
                    	$('#custname_error').hide();
                    }
                }
            });
		});

        //显示省市区
        E.region.init({
            p: 'provinceid',
            c: 'cityid',
            a: 'countyid'
        });

    });



    KindEditor.ready(function(K) {

        var kindEditor_upload = K.editor({
            allowFileManager : true,
            uploadJson: '/framework/kindeditor/php/upload_json.php?act=customer'
        });

        $(document).on('click', '#update_head_pic', function() {

            kindEditor_upload.loadPlugin('image', function() {
                kindEditor_upload.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {

                        $('#head_pic_box').html('<img src="' + url + '"> <a href="javascript: void(0);" id="del_head_pic">删除</a>').show();
                        $('#head_pic').val(url);
                        kindEditor_upload.hideDialog();

                    }
                });
            });

        });

        $(document).on('click', '#del_head_pic', function() {
            $('#head_pic_box').html('').hide();
            $('#head_pic').val('');
        });

    });

    var customer = {

        dt: "",

        check: function() {

            var provinceText=$("#provinceid").find("option:selected").text();
            var cityText=$("#cityid").find("option:selected").text();
            var countyText=$("#countyid").find("option:selected").text();
            if(provinceText == "请选择..."){
                $('#provinceName').val();
                $('#cityName').val();
                $('#countyName').val();
            }else if(cityText == "请选择..." ){
                $('#provinceName').val(provinceText);
                $('#cityName').val();
                $('#countyName').val();
            }else if(countyText == "请选择..."){
                $('#provinceName').val(provinceText);
                $('#cityName').val(cityText);
                $('#countyName').val();
            }else{
                $('#provinceName').val(provinceText);
                $('#cityName').val(cityText);
                $('#countyName').val(countyText);
            }

            this.dt = E.getFormValues("edit_form");

            var custID = $.trim( $("#custID").val() );
            var nickName = $.trim( $("#nickName").val() );
            var custname = $.trim( $("#custname").val() );
            var mobile = $.trim( $("#mobile").val() );
            var email = $.trim( $("#email").val() );
            var birthday = $.trim( $("#birthday").val() );
            var provinceid = $.trim( $("#provinceid").val() );
            var cityid = $.trim( $("#cityid").val() );
            var countyid = $.trim( $("#countyid").val() );
            var address = $.trim( $("#address").val() );
            var identityCard = $.trim( $("#identityCard").val() );
            var error_msg = "";

            if (custID == ""){
                error_msg += "请填写会员名<br>";
            }else if (!E.isMobile(custID)){
                error_msg += "会员名必须为手机号<br>";
            }

            if (custname == "")
                error_msg += "请填写会员真实姓名<br>";

           if( mobile != "" && !E.isMobile(mobile)){
                error_msg += "手机号码格式错误<br>";
            }

           if (email != "" && !E.isEmail(email)){
                error_msg += "邮箱格式错误<br>";
            }

            if (birthday == ""){
                error_msg += "请选择会员生日<br>";
            }else if(!E.isDate(birthday)){
                error_msg += "生日格式错误<br>";
            }

            if (provinceid == "" || cityid == "" || countyid == "")
                error_msg += "请选择所在的省市区<br>";

            if (address == "")
                error_msg += "请填写详细地址<br>";

            if (error_msg != "") {
                E.alert(error_msg);
            } else {
               this.add();
            }

        },

        add: function() {
            $.ajax({
                type: "GET",
                url: "/invokingAjax-backend/customer/customer.ajax?operFlg=100&act=add",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {

                        E.opener("customer.load");
                        E.alert(result_obj.message , 2 , "E.closeWindows()");

                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },
    };
    $('#birthday').datepicker();
</script>
</body>
</html>